<template>
  <div class="publish-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" icon="el-icon-plus" size="small" @click="handleAdd"> 新增</el-button>
      </el-col>
    </el-row>
    <el-table style="margin-top: 10px" v-loading="loading" :data="dataList">
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="最小值" align="center" prop="min" />
      <el-table-column label="最大值" align="center" prop="max" />
      <el-table-column label="名称" align="center" prop="name" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"> 编辑 </el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"> 删除 </el-button>
        </template>
      </el-table-column>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-table>
    <score-level-modal ref="modal" @ok="getList"></score-level-modal>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination/index.vue'
import ScoreLevelModal from '@/views/form/statistics/score/ScoreLevelModal.vue'
import { pageScoreLevel, deleteScoreLevel } from '@/api/project/score-level'

export default {
  name: 'ScoreLevel',
  components: { Pagination, ScoreLevelModal },
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      loading: false,
      type: '',
      formKey: '',
      dataList: [],
      url: {
        list: '/score-level/page'
      }
    }
  },
  created() {
    this.type = this.$route.query.type
    this.formKey = this.$route.query.key
    this.getList()
  },
  methods: {
    getList() {
      pageScoreLevel(this.formKey, this.queryParams).then((res) => {
        this.dataList = res.data.records
      })
    },
    handleAdd() {
      this.$refs.modal.add()
    },
    handleUpdate(row) {
      this.$refs.modal.form = row
      this.$refs.modal.update()
    },
    handleDelete(row) {
      deleteScoreLevel(row.id).then((res) => {
        if (res.code == 200) {
          this.$message.success('删除成功')
        }
      })
    }
  }
}
</script>

<style scoped></style>
